<?php
	class Userlogin extends Controller {
	    
		function login() {
		    
			$user_obj = $this->user_model->getByLogin($this->input->post('username'), $this->input->post('password'));

			$this->session->set_flashdata('login_message', !is_null($user_obj)?'login ok':'invalid username or password');
			$this->session->set_flashdata('username', $this->input->post('username'));
			$this->session->set_userdata('logged_in_user', serialize($user_obj));
			
			redirect($this->input->post('controller'));
		}
		
		function logout() {

			$this->session->set_flashdata('login_message', 'logged out');
			$this->session->unset_userdata('logged_in_user');
			
			redirect($this->input->post('controller'));
		}
	}

?>